<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>线索列表</title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <!-- 是否显示设置敞口按钮 -->
    <sys:funcAuth resCd="LinkCrAmt">
        <span id="isShowLinkCrAmtBtn"/>
    </sys:funcAuth>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div id="pageInTab" class="pageInTab">
        <div tabid="tabA" title="未拨打" lselected="true">
            <div class="searchArea">
                <form id="searchBar">
                    <div class="fieldset1 clearFix">
                        <%--<div class="fieldBox" id="searchPrjNmId">
                            <div class="label">编号</div>
                            <div class="field">
                                <input name="odrNo" id="odrNo" type="text" class="ui-textbox" value="">
                            </div>
                        </div>--%>
                        <div class="fieldBox" id="searchCstNmId" hidden="hidden">
                            <div class="label">是否拨打</div>
                            <div class="field">
                                <%--<input name="isFp" id="isFp" type="text" class="ui-textbox" value="0">--%>
                                <select name="isCall" id="isCall">
                                    <option value=" ">--请选择--</option>
                                    <option value="0" selected="selected">未拨打</option>
                                    <%--<c:forEach items="${odrStsCdList}" var="opt">
                                        <option value="${opt.key}">${opt.value}</option>
                                    </c:forEach>--%>
                                </select>
                            </div>
                        </div>
                        <div class="clearFix"></div>
                        <div class="btnsBox">
<%--                            <span id="searchBtn" class="sq-button sq-button-round">查询</span>--%>
<%--                            <span id="clearBtn" onclick="clearBtn();" class="sq-button sq-button-round">清空</span>--%>
                            <!-- <span id="download" class="sq-button sq-button-round">导出</span> -->
<%--                            <span id="exportDetailBtn" class="sq-button sq-button-round">导出</span>--%>
                            <%--批量分配按钮--%>
                            <%--<span id="batchFpBtn" class="sq-button sq-button-round">批量分配</span>--%>
                        </div>
                    </div>
                </form>
            </div>

            <div id="ligergrid1" class="sq-grid"></div>
        </div>
        <div tabid="tabB" title="已拨打" id="tabBId">
            <iframe frameborder="0" name="tabB" id="tabB" src=""></iframe>
        </div>
    </div>
</div>


<div id="chooseFlowDIV" style="display:none">
    <div id="ligergrid_flowStart" class="sq-grid"></div>
</div>
<div id="ywchange_result" style="display:none">
    <form id="ywchange_result_form">
    </form>
</div>
<script src="../js/ligerDateEditor.js" type="text/javascript"></script>
<script type="text/javascript">
    var grid = null;
    var callback = function () {
        grid.reload();
    };

    $("#download").click(function () {
        var form = new liger.get("searchBar");
        var data = form.getData();
        $.ajax({
            type: "post",
            url: '<%=path%>/carloan/odrclueinfo/download.do?',
            data: {}

        });
    });
    $(function () {
        $("#endTime").ligerDateEditor();
        $("#beginTime").ligerDateEditor();
    })

    var isShowLinkCrAmtBtn = $("#isShowLinkCrAmtBtn");
    var isLnkCompFlag = '${isLnkCompFlag}';
    if (isShowLinkCrAmtBtn.length && isLnkCompFlag && isLnkCompFlag == 1) {
        $("#compCrLim").show();
        $("#compCrLimText").show();
    }

    var grid = null;
    var queryFlag = '${queryFlag}'; //只查询列表
    var updateFlag = '${updateFlag}';//业务移交
    var updateSunFlag = '${updateSunFlag}';//供应商及账号修改
    var splPrjViewFlag = '${splPrjViewFlag}';//供应商项目页面
    var mgrPrjViewFlag = '${mgrPrjViewFlag}';//客户经理关联项目页面
    var isLnkPrjViewFlag = '${isLnkPrjViewFlag}';//挂靠公司管理项目页面
    var pageInApp = {}; // to 下一级子窗口 接口
    var pageInTab = null;
    $(function () {
        initTab();
        g = manager = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/carloan/odrphonenoteweb/initList.do',
            method: 'get',
            columns: [
                {
                    display: '公司名称', name: 'compNm', align: 'center', minWidth: 140,
                    enabledSort: true
                },
                {display: '所属区域', name: 'prnCd', minWidth: 140, align: 'center', enabledSort: true},
                {display: '所属城市', name: 'cyCd', minWidth: 140, align: 'center', enabledSort: true},
                {display: '联系人姓名', name: 'odrChannelInfoDTO.channelNm', minWidth: 100, enabledSort: true},
                {display: '联系人电话', name: 'odrChannelInfoDTO.channelMp', minWidth: 100, enabledSort: true},
                {
                    display: '公司ID',
                    name: 'id',
                    id: ' ',
                    minWidth: 140,
                    align: 'center',
                    enabledSort: true,
                    hide: true,
                },
                {
                    display: '联系人id',
                    name: 'odrChannelInfoDTO.id',
                    id: ' ',
                    minWidth: 140,
                    align: 'center',
                    enabledSort: true,
                     hide: true,
                },
                /*{display: '联系人电话', name: 'id', minWidth: 140, align: 'center', enabledSort: true},
                {display: '所属市', name: 'rgnCyCd', minWidth: 140, align: 'center', enabledSort: true},
                {display: '客户经理', name: 'cstMgrNm', minWidth: 140, align: 'center', enabledSort: true},
                {display: '客户经理手机号', name: 'cstMgrMp', minWidth: 140, align: 'center', enabledSort: true},
                {display: '创建时间', name: 'crtTm', width: 100, enabledSort: true, render:renderDate},
                {display: '期望贷款金额(万元)', name: 'contAmtD', width: 100, enabledSort: true},*/
                /*{display: '估值内容', name: 'content', width: 100, enabledSort: true},*/
                /* { display: '省公司', name: 'prOrgCdNm', width: 100 , enabledSort:true},
                 { display: '分公司', name: 'cyOrgCdNm', width: 100 , enabledSort:true},
                 { display: '项目类型', name: 'prjTypCdNm', width: 150, enabledSort:true},
                 { display: '业务模式', name: 'bizTypCdNm', minWidth: 140 , enabledSort:true},
                 { display: '预约状态', name: 'odrStsCdNm', minWidth: 100 , enabledSort:true},
                  { display: '申请单号', name: 'pNo', minWidth: 140 ,
                       render: function (rowdata, rowindex, value, column) {
                         var h = '';
                         if(value&&value!="null"){
                             h+='<a href="javascript:commShowFlow(';
                             h+="'"+rowdata.pInstId+"',";
                             h+="'"+rowdata.flowAudStsCd+"',";
                             h+="'"+rowdata.id+"'";
                             h+=')">'+value+'</a>'
                         }
                         return h;
                     },
                     enabledSort:true},
                 { display: '数据来源', name: 'dateResCdNm', minWidth: 100 , enabledSort:true},
                 { display: '创建时间', name: 'crtTm', minWidth: 100 , render:renderDate, enabledSort:true},*/
                getOptColumn()
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -20,
            checkbox: true,
            delayLoad: true,
            rownumbers: true
        });
        //   initOrgTree();
        grid = liger.get("ligergrid1");
        grid.setHeight(100);
        $("#searchBar").ligerForm();
        $("#searchBtn").click(function (event) {
            var call = $("#isCall").val();
            /*if(call=='1'){
                Add_navTab('tab_phone_xq', '已拨打', '<%=path%>/carloan/odrphonenoteweb/toCallPage.do');
            }*/
            var form = new liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            ;

            grid.reload();
        });
        var form = new liger.get("searchBar");
        var data = form.getData();
        for (name in data) {
            grid.setParm(name, data[name]);
        }
        ;
        grid.reload();
        /*批量分配*/
        $("#batchFpBtn").click(function (event) {
            var form = new liger.get("searchBar");
            var data = form.getData();

            var selecteds = g.getSelecteds();
            var usrId = '';
            for (var i = 0; i < selecteds.length; i++) {
                usrId += (selecteds[i].id) + "_";
            }

            $.ajax({
                type: 'POST',
                data: {
                    ids: usrId,
                    usrId:data.employ

                },
                dataType: 'json',
                url: '<%=path%>/carloan/odrcompinfo/distribute.do',
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    console.log(JSON.stringify(msg));
                    wait_dialog.close();
                    if (msg.success == 1) {
       //                 window.open(msg.data);
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        grid.reload();
//                        grid.reload($('.pcontrol input', grid.toolbar).val());
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });
        /*批量分配*/
    });

    var loadedTabs = [];

    //初始化Tab页签
    function initTab() {
        pageInTab = $("#pageInTab").ligerTab({
            height: 'auto',
            contextmenu: false,
            minIframeHeight: GET_minIframeHeight(),
            minIframeHeight: GET_minIframeHeight(),
            onBeforeSelectTabItem: function (tabid) {
                if(tabid!="tabA"){

                }
            },
            onAfterSelectTabItem: function(tabid) {
                if (loadedTabs.indexOf(tabid)<0) {
                    loadedTabs.push(tabid);
                    switch (tabid){
                        case "tabB":
                            pageInTab.setTabItemSrc(tabid, "<%=path%>/carloan/odrphonenoteweb/toCallPage.do");
                            break;
                    }
                };
                SetIframe_height();
            }
        });
        $.extend(true, pageInApp, {
            pageInTab: pageInTab
        });
        <%--Add_navTab('tab_phone_xq', '已拨打', '<%=path%>/carloan/odrphonenoteweb/toCallPage.do');--%>
    };

    //获取操作列
    function getOptColumn() {
            var column = {
                display: '填写',
                isSort: false,
                width: 150,
                align: 'center',
                render: function (rowdata, rowindex, value) {
                    var h = "";
                    h += '<a class="sq-button-hasicon" href="javascript:addPhoneNote(';
                    h += "'" + rowdata.id + "',"+"'"+(rowdata.odrChannelInfoDTO==null?'':rowdata.odrChannelInfoDTO.id)+"'";
                    h += ')"><i class="sqBtnIco_2"></i>填写</a>';
                    //yaoxr
                    /*var f = "";
                    f += '<a class="sq-button-hasicon" href="javascript:detailUpdateBtn(';
                    f += "'" + rowdata.clueId + "'";
                    f += ')"><i class="sqBtnIco_2"></i>编辑</a>';*/
                    return h;
                }
            }
            return column;

    }

    //显示流程
    function commShowFlow(_pInstId, _audStsCd, _businessKey) {
        if (StringUtils.isEmpty(_pInstId)) {
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var _formUrl = "/carloan/odrbscinfo/toAuditOdrInfoPage.do?isDetail=1" + "@@processInstanceId=" + _pInstId + "@@odrId=";
        var params = "?pInsId=" + _pInstId + "&status=" + _audStsCd + "&businessKey=" + _businessKey + "&formUrl=" + _formUrl;
        Add_navTab('tab_cst_invoice_flow_' + _businessKey, '查看流程', "<%=path%>/flow/flow/toFlowShowPageFowBus.do" + params);
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }

    function addPhoneNote(id,cstId) {
        var fromPrjFlag = true;
        var detailFlag = true;

        var _flag = $("#fromPrjFlagId").val();//来自哪里
        if (StringUtils.isNotEmpty(_flag)) {
            if (_flag == 'false') {
                fromPrjFlag = false;
            }
        }

        Add_navTab('tab_phone_add' + id, '添加拜访记录', '<%=path%>/carloan/odrphonenoteweb/toAddPage.do?cstId=' + cstId + '&&id=' + id + '&&detailFlag=' + detailFlag,callback);
    }

    function clearBtn() {
        $("#searchBar").ligerForm();
        var form = new liger.get("searchBar");
        form.setData({
            odrNo: " ",
            cstNm: " ",
            cstMgrNm: " ",
            odrStsCd: " ",
            firstUsrNm: " ",
            secondUsrNm: " ",
            buOrgCd: " ",
            beginTime: " ",
            endTime: " ",
        });
    }

    //发起流程 -yaoxr
    function addFlowStart(odrId) {
        if (!odrId) {
            $.ligerDialog.SQalert({content: "预约ID不能为空.", SQ_type: "warning"});
            return;
        }
        $.ligerDialog.confirm(FlowConstant.FLOW_ADD_START_CONFIRM, function (flag) {
            if (flag == false) {
                return;
            }
            ;
            var wait_dialog = $.ligerDialog.SQalert({
                content: LogUtils.LOG_CMM_DATA_LOADING,
                SQ_type: "waitting",
                onClose: function () {
                }
            });
            $.ajax({
                type: 'post',
                dataType: 'json',
                url: '<%=path%>/carloan/odrbscinfo/addFlowStart.do?odrId=' + odrId,
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {//成功发起流程
                        //UIUtils.alertSuccessHold1(msg.info);
                        var url = '<%=path%>/flow/flow/getFlowNextAssigne.do?key=' + msg.data;
                        FlowUtils.alertNextFlowAssign(url);
                        grid.reload();
                    } else if (msg.success == 0) {//错误
                        UIUtils.alertErrorHold1(msg.info);
                    }
                }
            });
        });
    }

</script>

</body>
</html>